﻿function isNumberKey(control_id, evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 45 || charCode > 47))
        return false;

    if (charCode == 46) {
        var dotcount = document.getElementById(control_id).value.split('.').length - 1;
        if (dotcount >= 1) {
            return false;
        }
    }
    return true;
}

function isDate(txtDateId) {
    // date length should be 10 characters - no more, no less            
    var Ctrl = document.getElementById(txtDateId);
    var txtDate = Ctrl.value;
    var flag = true;

    // extract day, month and year from the txtDate string
    // expected format is dd/mm/yyyy           
    var day = txtDate.substring(0, 2);
    var month = txtDate.substring(3, 5);
    var year = txtDate.substring(6, 10);

    if (txtDate.length != 10) {
        alert('Invalid Date');
        Ctrl.focus();
        flag = false;
    }
    // third and sixth character should be /
    else if (txtDate.substring(2, 3) != '/') {
        alert('Date Format is [ DD/MM/YYYY ]');
        Ctrl.focus();
        flag = false;
    }
    else if (txtDate.substring(5, 6) != '/') {
        alert('Date Format is [ DD/MM/YYYY ]');
        Ctrl.focus();
        flag = false;
    }
    //for have only 31 day
    else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
        if (day > 31) {
            alert('Date Should not be Greater than 31');
            Ctrl.focus();
            flag = false;
        }
    }
    //for have only 30 day
    else if (month == 4 || month == 6 || month == 9 || month == 11) {
        if (day > 30) {
            alert('Date Should not be Greater than 30');
            Ctrl.focus();
            flag = false;
        }
    }
    //for Febuary 
    else if (month == 2) {
        var leap = year % 4;
        if (leap == 0) {
            if (day > 29) {
                alert('february have only 29 days');
                Ctrl.focus();
                flag = false;
            }
        }
        else {
            if (day > 28) {
                alert('february have only 28 days');
                Ctrl.focus();
                flag = false;
            }
        }
    }
    else if (month > 12) {
        alert('Invalid Date');
        Ctrl.focus();
        flag = false;
    }
    // otherwise return true
    return flag;
}

/**
 * DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year


